package keter.mongo;

import java.net.UnknownHostException;

import com.jfinal.ext.plugin.monogodb.MongoKit;
import com.jfinal.ext.plugin.monogodb.MongodbPlugin;
import com.jfinal.log.Logger;
import com.mongodb.MongoClient;

public class KeterMongoPlugin extends MongodbPlugin{

	 private static final String DEFAULT_HOST = "127.0.0.1:27017";
	    protected final Logger logger = Logger.getLogger(getClass());

	    private MongoClient client;
	    private String host;
	    private String database;
	   
	    public KeterMongoPlugin(String host, String database) {
	    	super(DEFAULT_HOST);
	        this.host = host;
	        this.database = database;
	    }

	    @Override
	    public boolean start() {

	        try {
	            client = new MongoClient(host);
	        } catch (UnknownHostException e) {
	            throw new RuntimeException("can't connect mongodb, please check the host:" + host, e);
	        }

	        MongoKit.init(client, database);
	        return true;
	    }

}
